package com.hsytech.dijiebao.person.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class InformationDao {
	private DBHelper dbHpler;
	public static InformationDao informationDao;

	private InformationDao(Context context) {
		dbHpler = new DBHelper(context);
	}

	public static InformationDao getInstance(Context context) {

		if (informationDao == null) {
			informationDao = new InformationDao(context);
		}

		return informationDao;
	}

	/**
	 * ���
	 */
	public synchronized long add(Map<String, Object> map) {
		SQLiteDatabase db = dbHpler.getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("id", (String) map.get("id"));
		values.put("carorhotle", (String) map.get("carorhotle"));
		values.put("content", (String) map.get("content"));
		values.put("status", (String) map.get("status"));

		long rs = db.insert("INFORMATION", "INFORMATION", values);
		db.close();
		return rs;
	}

	/**
	 * ��ѯ
	 */
	public List<Map<String, Object>> queryAll() {
		List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();

		SQLiteDatabase db = dbHpler.getReadableDatabase();
		Cursor cr = db.rawQuery("SELECT * FROM " + "INFORMATION", null);
		Map<String, Object> map;
		while (cr.moveToNext()) {
			map = new HashMap<String, Object>();
			map.put("id", cr.getString(cr.getColumnIndex("id")));
			map.put("carorhotle", cr.getString(cr.getColumnIndex("carorhotle")));
			map.put("content", cr.getString(cr.getColumnIndex("content")));
			map.put("status", cr.getString(cr.getColumnIndex("status")));

			data.add(map);

		}

		cr.close();
		db.close();

		return data;

	}

	/**
	 * ���
	 */
	public void resetTable() {
		SQLiteDatabase db = dbHpler.getWritableDatabase();
		String str = "delete   from  " + "INFORMATION";
		db.execSQL(str);
		db.close();
	}

	/**
	 * ɾ��һ������
	 */
	public void delID(String delId) {
		SQLiteDatabase db = dbHpler.getWritableDatabase();
		String str = "delete   from  " + " INFORMATION " + " where " + " id "+" = " + delId;
		db.execSQL(str);
		db.close();
	}

	/**
	 * ��ѯid
	 */
	public String queryID() {

		SQLiteDatabase db = dbHpler.getReadableDatabase();
		// Map<String, Object> s=new HashMap<String, Object>();
		// ShufflingFirstBean sfb = new ShufflingFirstBean();
		String s = "0";
		Cursor cr = db.rawQuery("SELECT " + "id" + " FROM " + "INFORMATION", new String[] {});
		while (cr.moveToNext()) {

			// sfb.setId(cr.getString(cr.getColumnIndex(DBData.SHUFFING_FRONT_ID)));
			// sfb.setLastUpdateTime(cr.getString(cr.getColumnIndex(DBData.SHUFFING_FRONT_LAST_UPDATE_TIME)));
			// sfb.setCategory(cr.getString(cr.getColumnIndex(DBData.SHUFFING_FRONT_CATEGORY)));
			// sfb.setPicurl(cr.getString(cr.getColumnIndex(DBData.SHUFFING_FRONT_PICURL)));
			// sfb.setValue(cr.getString(cr.getColumnIndex(DBData.SHUFFING_FRONT_VALUE)));
			s = cr.getString(cr.getColumnIndex("id"));

		}
		cr.close();
		db.close();
		return s;
	}
}
